﻿Imports System.Data.SqlClient
Public Class clsCatalogoRutasOpto
    Private mintIdRutaOpto As Integer
    Private mintIdRuta As Integer
    Private mstrId_Ruta As String
    Private mstrCod_Ruta As String
    Private mstrDescripcion As String
    Public Property IdRutaOpto As Integer
        Get
            Return mintIdRutaOpto
        End Get
        Set(value As Integer)
            mintIdRutaOpto = value
        End Set
    End Property
    Public Property IdRuta As Integer
        Get
            Return mintIdRuta
        End Get
        Set(value As Integer)
            mintIdRuta = value
        End Set
    End Property
    Public Property Id_Ruta As String
        Get
            Return mstrId_Ruta
        End Get
        Set(value As String)
            mstrId_Ruta = value
        End Set
    End Property
    Public Property Cod_Ruta As String
        Get
            Return mstrCod_Ruta
        End Get
        Set(value As String)
            mstrCod_Ruta = value
        End Set
    End Property
    Public Property Descripcion As String
        Get
            Return mstrDescripcion
        End Get
        Set(value As String)
            mstrDescripcion = value
        End Set
    End Property
   
    Public Sub New()
        mintIdRutaOpto = 0
        mintIdRuta = 0
        mstrId_Ruta = ""
        mstrCod_Ruta = ""
        mstrDescripcion = ""
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into RutasOpto (IdRutaOpto," & _
                            "IdRuta," & _
                            "Id_Ruta," & _
                            "Cod_Ruta," & _
                            "Descripcion)" & _
                            "VALUES (" & _
                            "@IdRutaOpto," & _
                            "@IdRuta," & _
                            "@Id_Ruta," & _
                            "@Cod_Ruta," & _
                            "@Descripcion) "


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdRutaOpto", mintIdRutaOpto)
        Command.Parameters.AddWithValue("IdRuta", mintIdRuta)
        Command.Parameters.AddWithValue("Id_Ruta", mstrId_Ruta)
        Command.Parameters.AddWithValue("Cod_Ruta", mstrCod_Ruta)
        Command.Parameters.AddWithValue("Descripcion", mstrDescripcion)

        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar la ruta " & mstrDescripcion, MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
